package yunhe.servlet;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import yunhe.biz.ISaleBiz;
import yunhe.biz.impl.SaleBizImpl;
import yunhe.entity.EmpMsg;
import yunhe.entity.Sale;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;

/**
 * Created by Administrator on 2017/6/19.
 */
@WebServlet(name = "SaleListQueryServlet",urlPatterns = "/sale/SaleListQueryServlet")
public class SaleListQueryServlet extends HttpServlet {

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        ISaleBiz iSaleBizImpl = new SaleBizImpl();
        List<Sale> list = iSaleBizImpl.saleList();
        JSONArray ja=new JSONArray();

       for(Sale sale:list){
            JSONObject jbj=new JSONObject(sale);
            try {
                jbj.put("cusId",sale.getCustomer().getCusId());
                jbj.put("workId",sale.getEmpMsg().getWorkId());
            }catch (JSONException e){
                e.printStackTrace();
            }
           ja.put(jbj);
        }
        response.getWriter().print(ja.toString());
    }
}
